using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NTTHAO.Web.BL.CommonPage;

public partial class admin_webparts_Plug_ins_Comment_Default : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            string action = Request.QueryString["action"];
            string controlName = null;

            if ("delete".Equals(action, StringComparison.OrdinalIgnoreCase))
            {
                int id = 0;
                Int32.TryParse(Request.QueryString["id"], out id);
                this.DeleteComment(id);

                string redirectUrl = "?type=" + this.Request.QueryString["type"] + "&name=" + this.Request.QueryString["name"];
                Response.Redirect(redirectUrl, false);
                return;
            }

            if (controlName == null)
            {
                controlName = "CommentList.ascx";
            }

            if (controlName != null)
            {
                Control ctrl = LoadControl(controlName);
                this.Controls.Add(ctrl);
            }
        }
        catch (Exception ex) 
        {
            HtmlGenericControl ctrl = new HtmlGenericControl("div");
            ctrl.InnerHtml = "<p>" + ex.Message + "</p><p>" + ex.StackTrace.Replace(Environment.NewLine, "<br />");
            this.Controls.Add(ctrl);
        }
    }

    public void DeleteComment(int id)
    {
        try
        {
            ContentComment comment = new ContentComment(id);
            if (comment.ID > 0)
            {
                comment.Delete();
            }
        }
        catch { }
    }
}
